// JavaScript Document
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) {if (val.title!="") {nm=val.title;} else {nm=val.name;} if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- "'+nm+'" phải là một địa chỉ email.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- "'+nm+'" phải là một số.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- "'+nm+'" phải là số nằm giữa '+min+' và '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- Bạn chưa nhập "'+nm+'".\n'; }
  } if (errors) alert('Có những lỗi sau:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function check_all(start_loop, end_loop){
	for(i=start_loop; i<=end_loop; i++){
		try{
			document.getElementById("check_" + i).checked = true;
			document.getElementById("tr_" + i).className = "on_check";
		}
		catch(e){}
	}
}

function uncheck_all(start_loop, end_loop){
	for(i=start_loop; i<=end_loop; i++){
		try{
			document.getElementById("check_" + i).checked = false;
			document.getElementById("tr_" + i).className = "on_uncheck";
		}
		catch(e){}
	}
}

function change_bg(check_id, object_id){
	if(document.getElementById(check_id).checked == true){
		document.getElementById(object_id).className = "on_check";
	}
	else{
		document.getElementById(object_id).className = "on_uncheck";
	}
}

function creat_link(object){
	window.open("../create_link/create_link.php?object=" + object, "","width=700,height=600,menubar=0,resizable=1,scrollbars=1,statusbar=0,titlebar=0,toolbar=0");
}

function generate_percent(percent){
	width	= parseInt(percent * 2);
	document.write('<img align="absmiddle" hspace="5" src="../images/bg_percent.gif" width="' + width + '" height="16" />' + parseFloat(percent) + " %");
}

function more_picture(type, temp){
	url = (type == "add") ? "more_picture.php?type=add&temp=" + temp : "more_picture.php?type=edit&temp_id=" + temp;
	window.open(url, "", "width=700,height=600,menubar=0,resizable=1,scrollbars=1,statusbar=0,titlebar=0,toolbar=0");
}

// Frame left
function SwitchLeftFrame(){
	if(typeof(top.GetBarExpanded)!="undefined"){
		ExpandLeftFrame(!top.GetBarExpanded());
	}
}

function ExpandLeftFrame(f){
	var i = document.getElementById("imgLeftFrameSwitcher");
	if(i){
		top.FoldFrame(f);
		i.src = "../images/bar_" + (f?"close":"open") + ".gif";
	}
}

function SetExpandLeftFrame(){
	if(typeof(top.GetBarExpanded) != "undefined"){
		ExpandLeftFrame(top.GetBarExpanded());
	}
}

function GetCookie(sName){
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++){
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]) 
		return unescape(aCrumb[1]);
	}
	return null;
}

function ButtonLeftFrame(){
	cok = GetCookie("BarExpanded");
	img = (cok == "False") ? "open" : "close";
	document.write('<img title="Ẩn/hiện thanh menu quản trị" id="imgLeftFrameSwitcher" class="LeftFrameIcon" src="../images/bar_' + img + '.gif" onClick="SwitchLeftFrame();" onMouseOver="this.className=\'LeftFrameIcon_hover\'" onMouseOut="this.className=\'LeftFrameIcon\'" />');
}
-->